<template>
  <el-drawer :visible.sync="showRegister" title="处置登记" size="40%" @close="showRegister =false">
    <disposal-form ref="disposalForm" v-show="step === 0" :disposal-stat="disposalStat" @next="step = 1"/>
    <pro-form ref="proForm" v-show="step === 1" :disposal-stat="disposalStat" :pro-list="proList" @previous="step = 0"
              @submit="submit"
    />
  </el-drawer>
</template>

<script>
import CustomizeDisposalForm from '@/views/wms/deal/register/form/customizeDisposalForm'
import DisposalForm from '@/views/wms/deal/register/form/disposalForm'
import ProForm from '@/views/wms/deal/register/form/proForm'
import { disposalRegister } from '@/api/oms/dealTask'

export default {
  name: 'registerForm',
  dicts: ['deal_type'],
  props: {
    disposalStat: {
      type: [String, Number]
    },
    proList: {
      type: Array
    }
  },
  components: { ProForm, DisposalForm, CustomizeDisposalForm },
  data() {
    return {
      showRegister: false,
      step: 0
    }
  },
  methods: {
    submit() {
      const disposalForm = this.$refs.disposalForm.form
      let data = {
        disposalInfo: disposalForm,
        proList: this.proList.map(item => {
          return {
            taskId: item.taskId,
            proNo: item.proNo,
            disposalNumber: item.applyNumber,
            disposalAmount: item.disposalAmount
          }
        })
      }
      this.$refs.proForm.buttonLoading = true
      disposalRegister(data).then(() => {
        this.$modal.msgSuccess('登记成功')
        this.showRegister = false
        this.$refs.disposalForm.reset()
        this.$refs.disposalForm.$refs.fileUpload.reset()
        this.step = 0
        this.$emit('handSuccess')
      }).finally(() => {
        this.$refs.proForm.buttonLoading = false
      })
    }
  }
}
</script>

<style scoped>

</style>
